#pragma once
#include <stdint.h>
#include <sys/time.h>

class Timer {
public:
    Timer(const Timer& t) = delete;
    Timer operator=(const Timer& t) = delete;

    static Timer* get_instance(void) {
        static Timer timer;
        return &timer;
    }

    void begin(void) {
        struct timeval tv{};
        gettimeofday(&tv, nullptr);
        m_begin_time = tv.tv_sec * 1000 * 1000 + tv.tv_usec;
    }

    uint64_t end(void) {
        struct timeval tv{};
        gettimeofday(&tv, nullptr);
        m_end_time = tv.tv_sec * 1000 * 1000 + tv.tv_usec;
        return get_diff();
    }

    uint64_t get_diff(void) {
        return m_end_time - m_begin_time;
    }

private:
    Timer() = default;
    uint64_t m_begin_time{};
    uint64_t m_end_time{};
};